<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        body .el-table th.gutter {
            display: table-cell !important;
        }
    </style>
</head>
<body>
<div id="app">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

        <el-form-item label="详细描述" prop="type">
            <el-input v-model="queryParams.description"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>

    <el-table
            :data="tableData"
            style="width: 100%;"

            >
        <el-table-column
                prop="procInstId"
                label="实例ID"
                width="100">
        </el-table-column>
        <el-table-column
                prop="personId"
                label="员工ID"
                width="300">
        </el-table-column>
        <el-table-column
                prop="personName"
                label="员工名称"
                width="300">
        </el-table-column>
        <el-table-column
                prop="leaveDay"
                label="请假天数"
                width="300">
        </el-table-column>
        <el-table-column
                prop="dept"
                label="所属部门"
                width="300">
        </el-table-column>
        <el-table-column
                prop="description"
                label="详细描述"
                width="100">
        </el-table-column>

        <el-table-column
                prop="createTime"
                label="创建时间"
                width="300">
        </el-table-column>

        <el-table-column
                label="操作"
                width="300">
            <template slot-scope="scope">
                <el-button
                        @click.native.prevent="operateRow(scope.$index, tableData,'0')"
                        type="text"
                        size="small">
                    同意
                </el-button>
                <el-button
                        @click.native.prevent="operateRow(scope.$index, tableData,'1')"
                        type="text"
                        size="small">
                    驳回
                </el-button>
                </template>

        </el-table-column>

    </el-table>
    <el-pagination
            style="float:right"
            @current-change="changePage"
            :current-page="pageNum"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
    <!-- 添加或修改【请填写功能名称】对话框 -->

</div>
</body>
<!-- import Vue before Element -->
<script  src="js/axios.js"></script>
<script  src="js/vue.js"></script>
<script   src="js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',

        created(){
            this.getList();
        },
        data() {
            return {
                form:{},
                open:false,
                personId:"10001",
                queryParams:{
                     //页面自动获取当前登录人的ID
                    description:""
                },
                pageSize:10,
                pageNum:1,

                showSearch:true,
                tableData: [],
                total:0,


            }
        },
        methods: {

             cancel(){
                 this.open=false;
             },
            changePage(page){
                 this.pageNum=page;
                 this.getList();
            },
            operateRow (index, rows,flag){

               this.$confirm('是否确认操作实例ID为"' + rows[index].procInstId + '"的数据项?', "警告", {
                   confirmButtonText: "确定",
                   cancelButtonText: "取消",
                   type: "warning"
               }).then(()=> {
                   this.operate(rows[index].procInstId,flag);
               }).catch(() => {});
            },
            operate(procInstId,flag){
                axios.post(`/mybatisplus/leaveprocess/complete`,{
                    processId:procInstId,
                    flag:flag,
                   suggestion:""
                }).then(response => {
                    if(response.data.success){
                        this.$message({
                            message: "操作成功!",
                            type: 'success'
                        });
                        this.getList();
                    }else{
                        this.$message({
                            message: "操作失败!",
                            type: 'warning'
                        });
                    }

                }).catch(error => {
                    this.$message({
                        message: "操作异常",
                        type: 'error'
                    });

                })
            },


            /** 搜索按钮操作 */
            handleQuery() {
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.queryParams={};
               this.getList();
            },
            getList(){
                axios.post(`/mybatisplus/leaveprocess/getList`,
                    {
                        pageSize:this.pageSize,
                        pageNum:this.pageNum,
                        description:this.queryParams.description,
                         personId:this.personId,
                    }).then(response => {
                    this.tableData = response.data.queryResult.list;
                    this.total=response.data.queryResult.total;
                })
            }
        },
    })
</script>
</html>
